package cn.edu.hit.education.view;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.edu.hit.education.action.ExportScheduleAction;
import cn.edu.hit.education.contentprovider.ExScheduleContentProvider;
import cn.edu.hit.education.contentprovider.StatisticsInfoContentProvider;
import cn.edu.hit.education.labelprovider.ExScheduleLabelProvider;
import cn.edu.hit.education.labelprovider.StatisticsInfoLabelProvider;
import cn.edu.hit.education.listener.CourseDropTargetListener;
import cn.edu.hit.education.model.StatisticsInfo;
import cn.edu.hit.education.pojo.College;
import cn.edu.hit.education.pojo.Course;
import cn.edu.hit.education.pojo.ExCourse;
import cn.edu.hit.education.pojo.ExSchedule;
import cn.edu.hit.education.pojo.Schedule;
import cn.edu.hit.education.pojo.Semester;
import cn.edu.hit.education.pojo.Specialty;
import cn.edu.hit.education.pojo.University;
import cn.edu.hit.education.pojo.User;
import cn.edu.hit.education.service.ICollegeService;
import cn.edu.hit.education.service.ICourseService;
import cn.edu.hit.education.service.IScheduleService;
import cn.edu.hit.education.service.ISemesterService;
import cn.edu.hit.education.service.ISpecialtyService;
import cn.edu.hit.education.service.IUserSpeciatyService;
import cn.edu.hit.education.utils.StatisticsUtil;
import educationschedule.Application;

@Component
public class CourseScheduleView extends ViewPart implements ISelectionProvider {
	public static final String ID = "cn.edu.hit.education.view.CourseScheduleView";
	final Transfer[] transfer = new Transfer[] { LocalSelectionTransfer.getTransfer() };
	final Transfer[] transfer2 = new Transfer[] { TextTransfer.getInstance() };

	private Table tableSchedule;
	TableViewer tableViewerSchedule;
	private Table tableStatisticsInfo;
	TableViewer tableViewerStatisticsInfo;
	Combo comboSemester;

	@Autowired
	IScheduleService scheduleService;
	@Autowired
	ICourseService courseService;
	@Autowired
	ISemesterService semesterService;
	@Autowired
	ICollegeService collegeService;
	@Autowired
	ISpecialtyService specialtyService;
	@Autowired
	IUserSpeciatyService userSpeciatyService;

	private University university;
	private College college;
	private Specialty specialty;
	
	private List<College> colleges = new ArrayList<College>();
	private List<Specialty> specialties = new ArrayList<Specialty>();
	
	private Semester semester;
	List<Course> courses = new ArrayList<Course>();
	
	private Combo comboUniversity;
	private Combo comboCollege;
	private Combo comboSpecialty;

	List<ExSchedule> exSchedules = new ArrayList<ExSchedule>();
	List<StatisticsInfo> statisticsInfos = new ArrayList<StatisticsInfo>();
	
	private IAction exportScheduleAction = null;
	
	public CourseScheduleView() {

	}

	public void createPartControl(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new FormLayout());
		
		Composite composite_top = new Composite(composite, SWT.NONE);
		composite_top.setLayout(new GridLayout(8, false));
		FormData fd_composite_top = new FormData();
		fd_composite_top.top = new FormAttachment(0, 0);
		fd_composite_top.right = new FormAttachment(100, 0);
		fd_composite_top.left = new FormAttachment(0,0);
		fd_composite_top.bottom = new FormAttachment(70,0);
		composite_top.setLayoutData(fd_composite_top);

		Label label_1 = new Label(composite_top, SWT.NONE);
		label_1.setSize(24, 17);
		label_1.setText("学校");

		comboUniversity = new Combo(composite_top, SWT.NONE);
		comboUniversity.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,	false, 1, 1));
		comboUniversity.setSize(210, 25);

		Label label = new Label(composite_top, SWT.NONE);
		label.setSize(24, 17);
		label.setText("学院");

		comboCollege = new Combo(composite_top, SWT.NONE);
		comboCollege.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		comboCollege.setSize(208, 25);

		Label lblNewLabel_1 = new Label(composite_top, SWT.NONE);
		lblNewLabel_1.setSize(24, 17);
		lblNewLabel_1.setText("专业");

		comboSpecialty = new Combo(composite_top, SWT.NONE);
		comboSpecialty.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		comboSpecialty.setSize(208, 25);

		Label lblNewLabel = new Label(composite_top, SWT.NONE);
		lblNewLabel.setSize(24, 17);
		lblNewLabel.setText("学期");

		comboSemester = new Combo(composite_top, SWT.NONE);
		GridData gd_comboSemester = new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1);
		gd_comboSemester.widthHint = 204;
		comboSemester.setLayoutData(gd_comboSemester);
		comboSemester.setSize(210, 25);

		tableViewerSchedule = new TableViewer(composite_top, SWT.BORDER
				| SWT.FULL_SELECTION);
		tableSchedule = tableViewerSchedule.getTable();
		GridData gd_tableSchedule = new GridData(SWT.FILL, SWT.FILL, true, true, 8,
				1);
		gd_tableSchedule.heightHint = 85;
		tableSchedule.setLayoutData(gd_tableSchedule);
		tableSchedule.setSize(967, 319);
		tableSchedule.setLinesVisible(true);
		tableSchedule.setHeaderVisible(true);

		TableViewerColumn tableViewerColumn = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tableColumn = tableViewerColumn.getColumn();
		tableColumn.setWidth(100);
		tableColumn.setText("\u8BFE\u7A0B\u4EE3\u7801");

		TableViewerColumn tableViewerColumn_1 = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tableColumn_1 = tableViewerColumn_1.getColumn();
		tableColumn_1.setWidth(300);
		tableColumn_1.setText("\u8BFE\u7A0B\u540D\u79F0");

		TableViewerColumn tableViewerColumn_2 = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tableColumn_2 = tableViewerColumn_2.getColumn();
		tableColumn_2.setWidth(100);
		tableColumn_2.setText("\u5B66\u5206");

		TableViewerColumn tableViewerColumn_3 = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tableColumn_3 = tableViewerColumn_3.getColumn();
		tableColumn_3.setWidth(100);
		tableColumn_3.setText("\u5B66\u65F6");

		TableViewerColumn tableViewerColumn_4 = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tableColumn_4 = tableViewerColumn_4.getColumn();
		tableColumn_4.setWidth(100);
		tableColumn_4.setText("\u7406\u8BBA\u5B66\u65F6");

		TableViewerColumn tableViewerColumn_5 = new TableViewerColumn(
				tableViewerSchedule, SWT.NONE);
		TableColumn tblclmnNewColumn = tableViewerColumn_5.getColumn();
		tblclmnNewColumn.setWidth(100);
		tblclmnNewColumn.setText("实践学时");
		tableViewerSchedule.addDropSupport(DND.DROP_MOVE, transfer2,
				new CourseDropTargetListener(tableViewerSchedule, this));

		Menu contextMenu = new Menu(tableSchedule);
		tableSchedule.setMenu(contextMenu);

		MenuItem modifyItem = new MenuItem(contextMenu, SWT.None);
		modifyItem.setEnabled(false);
		modifyItem.setText("去除");
		modifyItem.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				TableItem[] selections = tableSchedule.getSelection();
				Shell parentShell = PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getShell();
				if (selections.length > 0) {
					for (TableItem tableItem : selections) {
						Course theCourse = (Course) tableItem.getData();

						List<Schedule> schedules = scheduleService
								.querySchedulesBySemesterCourseId(
										semester.getId(), theCourse.getId());
						// 获取当前可查看专业的Id
						List<Integer> specityIds = specialties.stream()
								.map(item -> {
									return item.getId();
								}).collect(Collectors.toList());

						schedules = schedules.stream().filter(item -> {
							return specityIds.contains(item.getSpecialtyId());
						}).collect(Collectors.toList());

						if (schedules != null && schedules.size() > 0) {
							for (Schedule schedule : schedules) {
								scheduleService.deleteByPrimaryKey(schedule
										.getId());
							}
						}
					}

					refreshData();
				}
			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
			}
		});

		tableSchedule.addListener(SWT.MouseDown, new Listener() {

			@Override
			public void handleEvent(Event event) {
				System.out.println(semester.getId());
				TableItem[] selections = tableSchedule.getSelection();
				if (selections.length > 0) {
					modifyItem.setEnabled(true);
				} else {
					modifyItem.setEnabled(false);
				}
			}
		});
		tableViewerSchedule.setContentProvider(new ExScheduleContentProvider());
		tableViewerSchedule.setLabelProvider(new ExScheduleLabelProvider());
		tableViewerSchedule.setInput(exSchedules);
		comboSemester.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				String semesterStr = comboSemester.getText();
				String[] rets = semesterStr.split(":");
				semester = semesterService.queryByPrimaryKey(Integer.parseInt(rets[2]));
				refreshData();
			}
		});
		comboSpecialty.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				specialty = specialties.get(comboSpecialty.getSelectionIndex());
				initSemesterCombo();
				clearAllSchedule();
			}
		});
		comboCollege.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				college = colleges.get(comboCollege.getSelectionIndex());
				if (specialties == null || specialties.size() != 1) {
					comboSpecialty.removeAll();
					specialties = specialtyService.querySpecialtiesByCollegeId(college.getId());
					initSpecialtyCombo(specialties);
				}
			}
		});

		Composite composite_bottom = new Composite(composite, SWT.NONE);
		FormData fd_composite_bottom = new FormData();
		fd_composite_bottom.top = new FormAttachment(70, 0);
		fd_composite_bottom.right = new FormAttachment(100, -5);
		fd_composite_bottom.bottom = new FormAttachment(100, 0);
		fd_composite_bottom.left = new FormAttachment(0, 5);
		composite_bottom.setLayoutData(fd_composite_bottom);
		composite_bottom.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		tableViewerStatisticsInfo = new TableViewer(composite_bottom, SWT.BORDER | SWT.FULL_SELECTION);
		tableStatisticsInfo = tableViewerStatisticsInfo.getTable();
		tableStatisticsInfo.setHeaderVisible(true);
		tableStatisticsInfo.setLinesVisible(true);
		
		TableViewerColumn tableViewerColumn_6 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tableColumn_5 = tableViewerColumn_6.getColumn();
		tableColumn_5.setWidth(100);
		tableColumn_5.setText("统计信息名称");
		
		TableViewerColumn tableViewerColumn_7 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tblclmnNewColumn_1 = tableViewerColumn_7.getColumn();
		tblclmnNewColumn_1.setWidth(100);
		tblclmnNewColumn_1.setText("学分");
		
		TableViewerColumn tableViewerColumn_8 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tblclmnNewColumn_2 = tableViewerColumn_8.getColumn();
		tblclmnNewColumn_2.setWidth(100);
		tblclmnNewColumn_2.setText("学时");
		
		TableViewerColumn tableViewerColumn_9 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tblclmnNewColumn_3 = tableViewerColumn_9.getColumn();
		tblclmnNewColumn_3.setWidth(100);
		tblclmnNewColumn_3.setText("理论学时");
		
		TableViewerColumn tableViewerColumn_10 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tblclmnNewColumn_4 = tableViewerColumn_10.getColumn();
		tblclmnNewColumn_4.setWidth(100);
		tblclmnNewColumn_4.setText("实践学时");
		
		TableViewerColumn tableViewerColumn_11 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tableColumn_6 = tableViewerColumn_11.getColumn();
		tableColumn_6.setWidth(100);
		tableColumn_6.setText("单位");
		
		TableViewerColumn tableViewerColumn_12 = new TableViewerColumn(tableViewerStatisticsInfo, SWT.NONE);
		TableColumn tableColumn_7 = tableViewerColumn_12.getColumn();
		tableColumn_7.setWidth(100);
		tableColumn_7.setText("方式");

		tableViewerStatisticsInfo.setContentProvider(new StatisticsInfoContentProvider());
		tableViewerStatisticsInfo.setLabelProvider(new StatisticsInfoLabelProvider());
		tableViewerStatisticsInfo.setInput(statisticsInfos);
		
		initDepartments();
		initSemesterCombo();
		
		// ///////////////

		makeActions();
		initializeToolBar();
	}

	private void makeActions() {
		exportScheduleAction = new ExportScheduleAction(exSchedules);
	}

	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars().getToolBarManager();
		toolbarManager.add(exportScheduleAction);
	}
	
	@Override
	public void setFocus() {

	}

	private List<Course> queryCourseBySememster(Specialty specialty,Semester semester) {
		List<Schedule> schedules = scheduleService.querySchedulesBySpecialtySemesterId(specialty.getId(),semester.getId());
		Set<Integer> allCourseIds = new HashSet<Integer>();
		List<Course> courses = new ArrayList<Course>();
		if (schedules != null && schedules.size() > 0) {
			for (Schedule schedule : schedules) {
				allCourseIds.add(schedule.getCourseId());
			}

			courses = courseService.queryCoursesByIds(allCourseIds);
		}
		return courses;
	}

	public void addNewCourse(int id) {
		Course course = courseService.queryCourseByPrimaryKey(id);

		if (!isSameCourse(course.getId(), 1, semester.getId())) {
			Schedule schedule = new Schedule();
			schedule.setCourseId(course.getId());
			schedule.setSpecialtyId(1);
			schedule.setSemesterId(semester.getId());
			schedule.setOpened(1);
			//
			schedule.setCredits(course.getCredits());
			schedule.setPeriod(course.getPeriod());
			schedule.setTheoretical(course.getTheoretical());
			schedule.setExperiment(course.getExperiment());
			scheduleService.insert(schedule);

			refreshData();
		} else {
			MessageDialog.openWarning(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "提示", "培养方案表格中已安排该课程！");
		}
	}

	private boolean isSameCourse(int courseId, int specialtyId, int semesterId) {
		List<Schedule> theSchedules = scheduleService.querySchedulesBySpecialtyId(specialtyId, 0);
		if (theSchedules != null && theSchedules.size() > 0) {
			for (Schedule schedule : theSchedules) {
				if (schedule.getCourseId() == courseId) {
					return true;
				}
			}
		}
		return false;
	}

	private void initSpecialty() {
		Subject subject = SecurityUtils.getSubject();
		// 角色是校长，可查看表中所有专业对应的课程信息
		if (subject.hasRole("principal")) {
			specialties = specialtyService.queryAllSpecialty();
			// 角色是院长，专业初始化为本学院下的所有专业！
		} else if (subject.hasRole("president")) {
			User user = (User) subject.getPrincipal();
			// 根据院长的用户Id查询到关联的专业Id
			List<Integer> ids = userSpeciatyService.querySpeciatyIdsByUser(user
					.getId());
			specialties = specialtyService.queryRelativeSpecialty(ids);
		} else if (subject.hasRole("director")) {
			User user = (User) subject.getPrincipal();
			// 根据普通用户的用户Id查询到关联的专业Id
			List<Integer> ids = userSpeciatyService.querySpeciatyIdsByUser(user
					.getId());
			specialties = specialtyService.queryRelativeSpecialty(ids);
		}
	}

	private void initSemesterCombo() {
		comboSemester.removeAll();
		List<Semester> semesters = semesterService.queryAllSemester();
		if (semesters != null && semesters.size() > 0) {
			semester = semesters.get(0);
			for (Semester semester : semesters) {
				comboSemester.add(semester.getGrade() + ":"	+ semester.getSemester() + ":" + semester.getId());
			}
		}
	}

	private void cloneCourseInformation(List<Course> courses,
			List<ExCourse> exCourses) {
		for (Course course : courses) {
			ExCourse exCourse = new ExCourse();
			exCourse.setId(course.getId());
			exCourse.setSpecialtyId(course.getSpecialtyId());
			exCourse.setPropertyId(course.getPropertyId());
			exCourse.setName(course.getName());
			exCourse.setCredits(course.getCredits());
			exCourse.setImportant(course.getImportant());
			exCourse.setNumber(course.getNumber());
			exCourse.setPeriod(course.getPeriod());
			exCourse.setTheoretical(course.getTheoretical());
			exCourse.setExperiment(course.getExperiment());
			exCourse.setUnit(course.getUnit());
			exCourse.setMethod(course.getMethod());
			exCourse.setStart(course.getStart());
			exCourse.setEnd(course.getEnd());
			exCourse.setClassroom(course.getClassroom());
			exCourse.setSelected(course.getSelected());
			exCourse.setNote(course.getNote());
			exCourses.add(exCourse);
		}
	}

	private void refreshData() {
		exSchedules = queryScheduleBySememster(specialty, semester);
		tableViewerSchedule.setInput(exSchedules);
		
		statisticsInfos = StatisticsUtil.processScheduleInformationData(exSchedules);
		tableViewerStatisticsInfo.setInput(statisticsInfos);
	}

	public Semester getSemester() {
		return semester;
	}

	@Override
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
		// TODO Auto-generated method stub
	}

	@Override
	public ISelection getSelection() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void removeSelectionChangedListener(
			ISelectionChangedListener listener) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setSelection(ISelection selection) {
		// TODO Auto-generated method stub

	}

	private List<Course> queryCourseBySememster(Semester semester2) {
		List<Schedule> schedules = scheduleService.querySchedulesBySemesterId(semester.getId());

		// 获取当前可查看专业的Id
		List<Integer> specityIds = specialties.stream().map(item -> {
			return item.getId();
		}).collect(Collectors.toList());
		// 过滤出当前用户可以查看的课程计划
		schedules = schedules.stream().filter(item -> {
			return specityIds.contains(item.getSpecialtyId());
		}).collect(Collectors.toList());

		Set<Integer> allCourseIds = new HashSet<Integer>();
		List<Course> courses = new ArrayList<Course>();
		if (schedules != null && schedules.size() > 0) {
			for (Schedule schedule : schedules) {
				allCourseIds.add(schedule.getCourseId());
			}

			courses = courseService.queryCoursesByIds(allCourseIds);
		}
		return courses;
	}

	private List<ExSchedule> queryScheduleBySememster(Specialty specialty, Semester semester) {
		List<Schedule> schedules = scheduleService.querySchedulesBySpecialtySemesterId(specialty.getId(), semester.getId());
		exSchedules.clear();
		
		if (schedules != null && schedules.size() > 0) {
			for (Schedule schedule : schedules) {
				ExSchedule exSchedule = new ExSchedule();
				exSchedule.setId(schedule.getId());
				exSchedule.setSpecialtyId(schedule.getSpecialtyId());
				exSchedule.setSemesterId(schedule.getSemesterId());
				exSchedule.setCourseId(schedule.getCourseId());
				exSchedule.setOpened(schedule.getOpened());
				exSchedule.setCredits(schedule.getCredits());
				exSchedule.setPeriod(schedule.getPeriod());
				exSchedule.setTheoretical(schedule.getTheoretical());
				exSchedule.setExperiment(schedule.getExperiment());
				exSchedule.setNote(schedule.getNote());
				exSchedule.setCourse(courseService.queryCourseByPrimaryKey(schedule.getCourseId()));
				exSchedules.add(exSchedule);
			}
		}
		return exSchedules;
	}
	
	private void initDepartments(){
		initUniversityCombo();
		initCollegeCombo();
		initSpecialtyCombo(null);
	}
	
	private void initUniversityCombo(){
		university = Application.authenticationInformation.getCurrentUniversity();
		if(university != null){// 有校长权限
			comboUniversity.add(university.getName());
			comboUniversity.select(0);
		}
	}
	
	private void initCollegeCombo(){
		colleges = Application.authenticationInformation.getCurrentColleges();
		if(colleges != null && colleges.size() > 0){//院长
			comboCollege.removeAll();
			for (College college : colleges) {
				comboCollege.add(college.getName());
			}
			
			if(colleges.size() == 1){
				comboCollege.select(0);
				college = colleges.get(0);
			}
		}	
	}
	
	private void initSpecialtyCombo(List<Specialty> specialties2){
		specialties = Application.authenticationInformation.getCurrentSpecialties();
		if(specialties2 != null){
			specialties = specialties2;
		}
		
		if(specialties != null && specialties.size() > 0){//系主任
			comboSpecialty.removeAll();
			for (Specialty specialty : specialties) {
				comboSpecialty.add(specialty.getName());
			}
			
			if(specialties.size() == 1){
				comboSpecialty.select(0);
				specialty = specialties.get(0);
			}
		}
	}
	
	private void clearAllSchedule(){
		exSchedules.clear();
		tableViewerSchedule.setInput(exSchedules);
		statisticsInfos.clear();
		tableViewerStatisticsInfo.setInput(statisticsInfos);
	}
}